package com.rx.mylist.service;

import cn.binarywang.wx.miniapp.api.WxMaQrcodeService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import com.alibaba.fastjson.JSON;
import com.rx.core.base.RxBaseConstant;
import com.rx.core.base.RxBaseData;
import com.rx.core.base.RxResponse;
import com.rx.core.dbase.RxBaseDbMust;
import com.rx.core.enm.HANDLER_TYPE;
import com.rx.core.enm.RESULT_CODE;
import com.rx.core.enm.RX_STATUS;
import com.rx.core.iface.NotReturnMode;
import com.rx.core.service.RxBaseAbstractService;
import com.rx.core.service.StandardService;
import com.rx.core.util.EmptyChecker;
import com.rx.core.util.RxUtil;
import com.rx.mylist.bean.AESUtil;
import com.rx.mylist.bean.OpenGId;
import com.rx.mylist.bean.WxConfigurations;
import com.rx.mylist.dao.ListEssayInfoMapper;
import com.rx.mylist.vo.*;
import com.rx.mylist.vo.relation.DoubleListGuardInfo;
import com.rx.mylist.vo.relation.DoubleListMemberInfo;
import com.rx.mylist.vo.relation.DoubleListOwnerInfo;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;

import java.io.File;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ListOwnerService extends ListBothService {



    private void checkImage(ListOwnerInfo listOwnerInfo) {
        if (EmptyChecker.isEmpty(listOwnerInfo.getFileName()) || EmptyChecker.isEmpty(listOwnerInfo.getPhone())) {
            listOwnerInfo.setStatus(OWNER_LIMIT);
        } else {
            listOwnerInfo.setStatus(OWNER_APPLY);
        }
    }

    private String getGroupBidByEDate(DoOwnerVo doOwnerVo, ListLoginVo appLogin) {

        if (EmptyChecker.isEmpty(doOwnerVo.getEncryptedData()) || EmptyChecker.isEmpty(doOwnerVo.getIv())) {
            return "";
        }

        String groupBid = "";
        try {
            groupBid = AESUtil.decrypt(doOwnerVo.getEncryptedData(), appLogin.getSessionKey(), doOwnerVo.getIv());
        } catch (Exception e) {

        }

        if (EmptyChecker.isEmpty(groupBid)) {
            // 重新获取getSessionKey

            RxUtil.CheckUtil.check(doOwnerVo.getCode(), RESULT_CODE.MESSAGE, "获取CODE");


            WxMaService wxMaService = ((WxMaService) wxConfiguration.wxService(wxConfiguration.wxMaConfig()));
            try {
                WxMaJscode2SessionResult session = wxMaService.getUserService().getSessionInfo(doOwnerVo.getCode());
                appLogin.setSessionKey(session.getSessionKey());
                cacheService.putData(appLogin.getToken(), appLogin);
            } catch (WxErrorException e) {
                log.info("获取SESSION_KEY 失败");
                RxUtil.CheckUtil.check(doOwnerVo.getCode(), RESULT_CODE.MESSAGE, "重新获取CODE");
            }
            try {
                groupBid = AESUtil.decrypt(doOwnerVo.getEncryptedData(), appLogin.getSessionKey(), doOwnerVo.getIv());
            } catch (Exception e) {

            }
        }

        if (EmptyChecker.isEmpty(groupBid)) {
            // 解码失败
            log.info("解码失败，获取不到群ID");
            return "";
        }

        try {
            OpenGId openGId = JSON.parseObject(groupBid, OpenGId.class);

            return openGId.getOpenGId();
        } catch (Exception e) {

        }
        return "";

    }

    public static String reverse(String s) {

        if (EmptyChecker.isEmpty(s)) {
            return "";
        }

        char[] c = s.toCharArray();
        int begin = 0;
        int end = c.length > 5 ? 5 : c.length;
        char temp;
        while (end > begin) {
            temp = c[begin];
            c[begin] = c[end];
            c[end] = temp;
            end--;
            begin++;
        }
        return new String(c);
    }

    private List<String> getOwnerFilter() {
        List<String> filterList = new ArrayList<>();
        filterList.addAll(Arrays.asList(
                RxUtil.StringUtil.lineToHump(ListOwnerInfo.UPDATE_DATE),
                RxUtil.StringUtil.lineToHump(ListOwnerInfo.VALID),
                RxUtil.StringUtil.lineToHump(ListOwnerInfo.PHONE.toLowerCase())));

        filterList.add(RxUtil.StringUtil.lineToHump(ListOwnerInfo.MANAGE_KEY_RANDOM.toLowerCase()));
        filterList.add(RxUtil.StringUtil.lineToHump(ListOwnerInfo.KEY_RANDOM.toLowerCase()));
        filterList.add(RxUtil.StringUtil.lineToHump(ListOwnerInfo.PROPERTY_KEY_RANDOM.toLowerCase()));
        return filterList;
    }

    private void filterReturn(ListOwnerInfo listOwnerInfo, String hide) {


        if (HIDE_KEY.equalsIgnoreCase(hide)) {
            listOwnerInfo.setEncrypt(reverse(listOwnerInfo.getKeyRandom()));
        } else if (HIDE_MANA_KEY.equalsIgnoreCase(hide)) {
            listOwnerInfo.setEncrypt(reverse(listOwnerInfo.getManageKeyRandom()));
        } else if (HIDE_PROPERTY_KEY.equalsIgnoreCase(hide)) {
            listOwnerInfo.setEncrypt(reverse(listOwnerInfo.getPropertyKeyRandom()));
        } else {

        }

        listOwnerInfo.appendFilter(getOwnerFilter());
    }

    public Object doOwner(DoOwnerVo doOwnerVo) throws IllegalAccessException, InstantiationException {

        RxUtil.CheckUtil.check(doOwnerVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doOwnerVo.getOwnerInfo(), RESULT_CODE.MESSAGE, "无信息");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doOwnerVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }

        String groupBid = getGroupBidByEDate(doOwnerVo, appLogin);
        if (EmptyChecker.isEmpty(groupBid)) {
            RxUtil.CheckUtil.check(doOwnerVo.getOwnerInfo().getGroupId(), RESULT_CODE.MESSAGE, "无群ID");
        } else {
            doOwnerVo.getOwnerInfo().setGroupId(groupBid);
        }


        ListOwnerInfo listOwnerInfo = (ListOwnerInfo) ListOwnerInfo.create(ListOwnerInfo.class, HANDLER_TYPE.SINGLE_DETAIL);
        listOwnerInfo.getHandlerController().onlyDefault();
        listOwnerInfo.setBid(doOwnerVo.getOwnerInfo().getBid());
        listOwnerInfo.setGroupId(doOwnerVo.getOwnerInfo().getGroupId());
        Object obj = standardService.detail(listOwnerInfo);


        if (obj instanceof RxResponse) {
            listOwnerInfo = doOwnerVo.getOwnerInfo();
            listOwnerInfo.setUserBid(appLogin.getBid());
            listOwnerInfo.setManageGroupId("0");
            listOwnerInfo.setPropertyGroupId("0");
            checkImage(listOwnerInfo);
            listOwnerInfo.resetHandlerType(HANDLER_TYPE.SINGLE_INSERT);
            standardService.insert(listOwnerInfo);
        } else {
            listOwnerInfo = (ListOwnerInfo) obj;
            cacheService.deleteHomeData(listOwnerInfo.getBid());

            if (appLogin.getBid().equalsIgnoreCase(listOwnerInfo.getUserBid())) {
                listOwnerInfo.setFileName(doOwnerVo.getOwnerInfo().getFileName());
                listOwnerInfo.setPhone(doOwnerVo.getOwnerInfo().getPhone());
                listOwnerInfo.setName(doOwnerVo.getOwnerInfo().getName());
                listOwnerInfo.setKeyRandom(doOwnerVo.getOwnerInfo().getKeyRandom());
                listOwnerInfo.setManageKeyRandom(doOwnerVo.getOwnerInfo().getManageKeyRandom());
                listOwnerInfo.setPropertyKeyRandom(doOwnerVo.getOwnerInfo().getPropertyKeyRandom());
                checkImage(listOwnerInfo);
                listOwnerInfo.resetHandlerType(HANDLER_TYPE.SINGLE_UPDATE);
                standardService.update(listOwnerInfo);
            } else {
                RxUtil.CheckUtil.condition(true, RESULT_CODE.MESSAGE, "该群已经被创建");
            }

        }
        filterReturn(listOwnerInfo, "");
        return listOwnerInfo;
    }

    public Object ownerPage(@RequestBody DoOwnerVo doOwnerVo) throws IllegalAccessException, InstantiationException {

        RxUtil.CheckUtil.check(doOwnerVo.getToken(), RESULT_CODE.MESSAGE, "未登录");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doOwnerVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }

        ListOwnerInfo listOwnerInfo = (ListOwnerInfo) ListOwnerInfo.create(ListOwnerInfo.class, HANDLER_TYPE.SINGLE_PAGE);
        listOwnerInfo.getHandlerController().onlyDefault();
        listOwnerInfo.setUserBid(appLogin.getBid());
        listOwnerInfo.setPageNum(listOwnerInfo.getPageNum() == null ? 1 : listOwnerInfo.getPageNum());
        listOwnerInfo.setPageSize(listOwnerInfo.getPageSize() == null ? 10 : listOwnerInfo.getPageSize());

        RxUtil.SQL.desc(listOwnerInfo, "id");

        Object obj = standardService.searchPage(listOwnerInfo);

        List list = RxUtil.result(obj);
        for (int i = 0; i < list.size(); i++) {
            ListOwnerInfo info = (ListOwnerInfo) list.get(i);
            filterReturn(info, "");
        }
        return list;
    }
    public Object ownerMpConnect(@RequestBody DoOwnerVo doOwnerVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doOwnerVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doOwnerVo.getOwnerInfo(), RESULT_CODE.MESSAGE, "无信息");
        RxUtil.CheckUtil.check(doOwnerVo.getOwnerInfo().getBid(), RESULT_CODE.MESSAGE, "无指定业主圈");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doOwnerVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }

        ListOwnerInfo old = (ListOwnerInfo) ListOwnerInfo.create(ListOwnerInfo.class, HANDLER_TYPE.SINGLE_DETAIL);
        old.getHandlerController().onlyDefault();
        old.setBid(doOwnerVo.getOwnerInfo().getBid());
        Object obj = standardService.detail(old);
        if (obj instanceof RxResponse) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.MESSAGE, "业主圈不存在");
        }
        old = (ListOwnerInfo)obj;

        RxUtil.CheckUtil.condition(!old.getUserBid().equalsIgnoreCase(doOwnerVo.getOwnerInfo().getUserBid()), RESULT_CODE.MESSAGE, "您无权确认");


        ListOwnerInfo listOwnerInfo = doOwnerVo.getOwnerInfo();
        listOwnerInfo.setUserBid(appLogin.getBid());
        listOwnerInfo.resetHandlerType(HANDLER_TYPE.SINGLE_UPDATE);
        listOwnerInfo.getHandlerController().onlyDefault();
        return standardService.update(listOwnerInfo);
    }

    public Object ownerConnect(@RequestBody DoOwnerVo doOwnerVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doOwnerVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doOwnerVo.getOwnerInfo(), RESULT_CODE.MESSAGE, "无信息");
        RxUtil.CheckUtil.check(doOwnerVo.getOwnerInfo().getBid(), RESULT_CODE.MESSAGE, "无指定业主圈");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doOwnerVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }

        RxUtil.CheckUtil.condition(!appLogin.getBid().equalsIgnoreCase(doOwnerVo.getOwnerInfo().getUserBid()), RESULT_CODE.MESSAGE, "您无权确认");

        doOwnerVo.getOwnerInfo().setUserBid(null);

        String groupBid = getGroupBidByEDate(doOwnerVo, appLogin);
        RxUtil.CheckUtil.check(groupBid, RESULT_CODE.MESSAGE, "无群ID");
        if ("02".equalsIgnoreCase(doOwnerVo.getOperate())) {
            doOwnerVo.getOwnerInfo().setManageGroupId(groupBid);
        } else if ("03".equalsIgnoreCase(doOwnerVo.getOperate())) {
            doOwnerVo.getOwnerInfo().setPropertyGroupId(groupBid);
        }

        doOwnerVo.getOwnerInfo().setEncrypt(reverse(doOwnerVo.getOwnerInfo().getKeyRandom()));
        doOwnerVo.getOwnerInfo().setEncrypt(reverse(doOwnerVo.getOwnerInfo().getManageKeyRandom()));
        doOwnerVo.getOwnerInfo().setEncrypt(reverse(doOwnerVo.getOwnerInfo().getPropertyKeyRandom()));


        ListOwnerInfo listOwnerInfo = doOwnerVo.getOwnerInfo();

        listOwnerInfo.resetHandlerType(HANDLER_TYPE.SINGLE_UPDATE);
        listOwnerInfo.getHandlerController().onlyDefault();
        return standardService.update(listOwnerInfo);
    }

    public Object keySecret(@RequestBody DoOwnerVo doOwnerVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doOwnerVo.getToken(), RESULT_CODE.MESSAGE, "未登录");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doOwnerVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }

        String groupBid = getGroupBidByEDate(doOwnerVo, appLogin);
        RxUtil.CheckUtil.check(groupBid, RESULT_CODE.MESSAGE, "无群ID");

        ListOwnerInfo listOwnerInfo = (ListOwnerInfo) ListOwnerInfo.create(ListOwnerInfo.class, HANDLER_TYPE.SINGLE_LIST);
        listOwnerInfo.getHandlerController().onlyDefault();
        // 业主权限
        listOwnerInfo.setGroupId(groupBid);
        Object ownerObject = standardService.searchList(listOwnerInfo);
        List<ListOwnerInfo> ownerList = RxUtil.result(ownerObject);
        for (ListOwnerInfo ownerInfo : ownerList) {
            filterReturn(ownerInfo, HIDE_KEY);
        }
        // 业委权限
        listOwnerInfo.setGroupId(null);
        listOwnerInfo.setManageGroupId(groupBid);
        Object ownerCommitteeObject = standardService.searchList(listOwnerInfo);
        List<ListOwnerInfo> ownerCommitteeList = RxUtil.result(ownerCommitteeObject);
        for (ListOwnerInfo ownerInfo : ownerCommitteeList) {
            filterReturn(ownerInfo, HIDE_MANA_KEY);
        }
        // 物业权限
        listOwnerInfo.setManageGroupId(null);
        listOwnerInfo.setPropertyGroupId(groupBid);
        Object propertyObject = standardService.searchList(listOwnerInfo);
        List<ListOwnerInfo> propertyList = RxUtil.result(propertyObject);
        for (ListOwnerInfo ownerInfo : propertyList) {
            filterReturn(ownerInfo, HIDE_PROPERTY_KEY);
        }
        KeySecreteVo keySecreteVo = new KeySecreteVo();
        keySecreteVo.setOwnerList(ownerList);
        keySecreteVo.setCommitteeList(ownerCommitteeList);
        keySecreteVo.setPropertyList(propertyList);

        return keySecreteVo;
    }

    public Object checkSecret(@RequestBody DoOwnerVo doOwnerVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doOwnerVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doOwnerVo.getScene(), RESULT_CODE.MESSAGE, "Scene必输");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doOwnerVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }


        if ("04".equalsIgnoreCase(doOwnerVo.getOperate())) {
            // 物业校验0

            DoubleListOwnerInfo condition = (DoubleListOwnerInfo) RxBaseData.create(DoubleListOwnerInfo.class, ListGuardInfo.class, HANDLER_TYPE.DOUBLE_LIST);

            ((ListGuardInfo) condition.obtainRelation()).setScene(doOwnerVo.getScene());
            ((ListGuardInfo) condition.obtainRelation()).setStatus(RX_STATUS.NORMAL.getCode());

            condition.setReturnType(DoubleListGuardInfo.ASS_BID);
            // 不查询某个字段
            condition.appendSqlFilter(Arrays.asList(ListOwnerInfo.UPDATE_DATE, ListOwnerInfo.VER, ListOwnerInfo.VALID,
                    ListOwnerInfo.PHONE, ListOwnerInfo.FILE_NAME, ListOwnerInfo.ID_RANDOM,
                    ListOwnerInfo.GROUP_ID, ListOwnerInfo.MANAGE_GROUP_ID, ListOwnerInfo.PROPERTY_GROUP_ID,
                    ListOwnerInfo.USER_BID));

            // 不查询第二张表
            condition.removeSecondTableField();
            condition.getHandlerController().onlyDefault();
            List<DoubleListOwnerInfo> list = RxUtil.result(standardService.innerSearchList(condition));
            if (EmptyChecker.notEmpty(list)) {

                DoubleListOwnerInfo result = list.get(0);

                result.setKeyRandom(RxUtil.EncryptUtil.toMD5(appLogin.getToken() + result.getKeyRandom()));
                result.setManageKeyRandom(RxUtil.EncryptUtil.toMD5(appLogin.getToken() + result.getManageKeyRandom()));
                result.setPropertyKeyRandom(RxUtil.EncryptUtil.toMD5(appLogin.getToken() + result.getPropertyKeyRandom()));

                return result;
            }

            //RxUtil.EncryptUtil.toMD5(appLogin.getToken() + listOwnerInfo.getKeyRandom())
        }


        return 1;
    }

    private boolean checkMd5(ListLoginVo appLogin, ListOwnerInfo listOwnerInfo, String md5, boolean update) {

        if (EmptyChecker.isEmpty(appLogin) || EmptyChecker.isEmpty(md5)) {
            return false;
        }

        if (update) {
            return md5.equalsIgnoreCase(RxUtil.EncryptUtil.toMD5(appLogin.getToken() + listOwnerInfo.getManageKeyRandom())) ||
                    md5.equalsIgnoreCase(RxUtil.EncryptUtil.toMD5(appLogin.getToken() + listOwnerInfo.getPropertyKeyRandom()));
        } else {
            return md5.equalsIgnoreCase(RxUtil.EncryptUtil.toMD5(appLogin.getToken() + listOwnerInfo.getKeyRandom()));
        }
    }
    private boolean checkMd5(ListLoginVo appLogin, ListOwnerInfo listOwnerInfo, String md5) {

        if (EmptyChecker.isEmpty(appLogin) || EmptyChecker.isEmpty(md5)) {
            return false;
        }

        if(md5.equalsIgnoreCase(RxUtil.EncryptUtil.toMD5(appLogin.getToken() + listOwnerInfo.getManageKeyRandom()))){
            return true;
        }

        if(md5.equalsIgnoreCase(RxUtil.EncryptUtil.toMD5(appLogin.getToken() + listOwnerInfo.getPropertyKeyRandom()))){
            return true;
        }
        return md5.equalsIgnoreCase(RxUtil.EncryptUtil.toMD5(appLogin.getToken() + listOwnerInfo.getKeyRandom()));

    }
    private boolean checkMd5(ListLoginVo appLogin, ListOwnerInfo listOwnerInfo, String md5,String share) {

        if (EmptyChecker.isEmpty(appLogin) || EmptyChecker.isEmpty(md5)) {
            return false;
        }

        if("02".equalsIgnoreCase(share)&&md5.equalsIgnoreCase(RxUtil.EncryptUtil.toMD5(appLogin.getToken() + listOwnerInfo.getManageKeyRandom()))){
            return true;
        }

        if("03".equalsIgnoreCase(share)&&md5.equalsIgnoreCase(RxUtil.EncryptUtil.toMD5(appLogin.getToken() + listOwnerInfo.getPropertyKeyRandom()))){
            return true;
        }
        return "01".equalsIgnoreCase(share)&&md5.equalsIgnoreCase(RxUtil.EncryptUtil.toMD5(appLogin.getToken() + listOwnerInfo.getKeyRandom()));

    }

    private ListOwnerInfo getAssOwner(String bid) throws IllegalAccessException, InstantiationException {

        ListOwnerInfo ownerInfo = (ListOwnerInfo)cacheService.getHomeData(bid);
        if(EmptyChecker.notEmpty(ownerInfo)){
            return ownerInfo;
        }

        ListOwnerInfo listOwnerInfo = (ListOwnerInfo) ListOwnerInfo.create(ListOwnerInfo.class, HANDLER_TYPE.SINGLE_LIST);
        listOwnerInfo.getHandlerController().onlyDefault();
        listOwnerInfo.setBid(bid);

        Object object = standardService.searchList(listOwnerInfo);
        List<ListOwnerInfo> list = RxUtil.result(object);
        if (EmptyChecker.isEmpty(list)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.MESSAGE, "关联不存在,请重新操作");
        }
        cacheService.putHomeData(bid,list.get(0));
        return list.get(0);
    }
    @Transactional
    public Object saveGuard(@RequestBody DoOwnerVo doOwnerVo) throws IllegalAccessException, InstantiationException {

        RxUtil.CheckUtil.check(doOwnerVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doOwnerVo.getListGuardInfo(), RESULT_CODE.MESSAGE, "无门禁信息");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doOwnerVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }

        ListOwnerInfo listOwnerInfo = getAssOwner(doOwnerVo.getListGuardInfo().getAssBid());
        if (!checkMd5(appLogin, listOwnerInfo, doOwnerVo.getCheckCode(), true)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.DENIED,"share02,share03");
        }

        if (EmptyChecker.isEmpty(doOwnerVo.getListGuardInfo().getStatus())) {
            doOwnerVo.getListGuardInfo().setStatus(RX_STATUS.NORMAL.getCode());
        }

        ListGuardInfo guardInfo = doOwnerVo.getListGuardInfo();
        return createQr(guardInfo);

    }

    public Object guardPage(@RequestBody DoOwnerVo doOwnerVo) throws IllegalAccessException, InstantiationException {

        RxUtil.CheckUtil.check(doOwnerVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doOwnerVo.getBid(), RESULT_CODE.MESSAGE, "无小区");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doOwnerVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }


        ListOwnerInfo listOwnerInfo = getAssOwner(doOwnerVo.getBid());
        if (!checkMd5(appLogin, listOwnerInfo, doOwnerVo.getCheckCode())) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.DENIED,"share01,share02,share03");
        }

        DoubleListOwnerInfo condition = (DoubleListOwnerInfo) RxBaseData.create(DoubleListOwnerInfo.class, ListGuardInfo.class, HANDLER_TYPE.DOUBLE_PAGE);

        condition.setPageSize(doOwnerVo.getPageSize());
        condition.setPageNum(doOwnerVo.getPageNum());

        condition.setReturnType(DoubleListGuardInfo.ASS_BID);
        // 不查询第二张表
        //condition.removeTableField();
        // 不查询某个字段
        condition.appendSqlFilter(Arrays.asList(ListOwnerInfo.UPDATE_DATE, ListOwnerInfo.VER, ListOwnerInfo.VALID,
                ListOwnerInfo.PHONE, ListOwnerInfo.FILE_NAME, ListOwnerInfo.KEY_RANDOM, ListOwnerInfo.ID_RANDOM,
                ListOwnerInfo.GROUP_ID, ListOwnerInfo.MANAGE_GROUP_ID, ListOwnerInfo.PROPERTY_GROUP_ID,
                ListOwnerInfo.MANAGE_KEY_RANDOM, ListOwnerInfo.PROPERTY_KEY_RANDOM, ListOwnerInfo.USER_BID));


        condition.setBid(doOwnerVo.getBid());
        condition.getHandlerController().onlyDefault();

        ListGuardInfo listGuardInfo = (ListGuardInfo) condition.getRelation();
        listGuardInfo.setStatus(RX_STATUS.NORMAL.getCode());
        listGuardInfo.appendSqlFilter(Arrays.asList(ListGuardInfo.IMAGE.toLowerCase()));


        return RxUtil.result(standardService.innerSearchPage(condition));
    }

    public Object guardImage(@RequestBody DoOwnerVo doOwnerVo) throws IllegalAccessException, InstantiationException {

        RxUtil.CheckUtil.check(doOwnerVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doOwnerVo.getBid(), RESULT_CODE.MESSAGE, "无单位");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doOwnerVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }
        ListGuardInfo listGuardInfo = (ListGuardInfo) ListGuardInfo.create(ListGuardInfo.class, HANDLER_TYPE.SINGLE_DETAIL);
        listGuardInfo.setBid(doOwnerVo.getBid());
        listGuardInfo.setStatus(RX_STATUS.NORMAL.getCode());

        Object obj = standardService.detail(listGuardInfo);
        if (obj instanceof RxResponse) {
            return obj;
        }
        ListGuardInfo result = (ListGuardInfo) obj;
        result.appendFilter(Arrays.asList(
                RxUtil.StringUtil.lineToHump(ListGuardInfo.UPDATE_DATE),
                RxUtil.StringUtil.lineToHump(ListGuardInfo.VER),
                RxUtil.StringUtil.lineToHump(ListGuardInfo.VALID),
                RxUtil.StringUtil.lineToHump(ListGuardInfo.BID),
                RxUtil.StringUtil.lineToHump(ListGuardInfo.ASS_BID_),
                RxUtil.StringUtil.lineToHump(ListGuardInfo.NAME),
                RxUtil.StringUtil.lineToHump(ListGuardInfo.SCENE)
        ));
        return result;
    }

    private boolean hasHomerExist(ListLoginVo appLogin, String bid, String buildingNo, String homeNo) throws IllegalAccessException, InstantiationException {

        ListHomeInfo listHomeInfo = (ListHomeInfo) ListHomeInfo.create(ListHomeInfo.class, HANDLER_TYPE.SINGLE_LIST);
        listHomeInfo.getHandlerController().onlyDefault();
        listHomeInfo.setOwnerBid(bid);
        listHomeInfo.setBuildingNo(buildingNo);
        listHomeInfo.setHomeNo(homeNo);

        Object object = standardService.searchList(listHomeInfo);
        List<ListHomeInfo> list = RxUtil.result(object);
        if (EmptyChecker.notEmpty(list)) {

            for (ListHomeInfo homeInfo : list) {
                RxUtil.CheckUtil.condition(homeInfo.getUserBid().equalsIgnoreCase(appLogin.getBid()),
                        RESULT_CODE.MESSAGE, "您已绑定！");
            }
            return true;
        }

        return false;
    }

    private void updateRealName(ListLoginVo appLogin, String name,String phone) throws IllegalAccessException, InstantiationException {
        //RxUtil.CheckUtil.check(listHomeInfo.getName(), RESULT_CODE.MESSAGE, "请输入姓名");

        boolean needUpdate = false;
        if (EmptyChecker.notEmpty(name)) {
            if (!name.equalsIgnoreCase(appLogin.getRealName())) {
                needUpdate = true;
            }
        }

        if (EmptyChecker.notEmpty(phone)) {
            if (!phone.equalsIgnoreCase(appLogin.getPhone())) {
                needUpdate = true;
            }
        }

        if (needUpdate) {
            ListAccountInfo mineAccuScores = (ListAccountInfo) ListAccountInfo.create(ListAccountInfo.class, HANDLER_TYPE.SINGLE_UPDATE);
            mineAccuScores.setBid(appLogin.getBid());
            mineAccuScores.setVer(appLogin.getVer());
            mineAccuScores.setRealName(name);
            mineAccuScores.setPhone(phone);

            mineAccuScores.getHandlerController().onlyDefault();
            Object object = standardService.update(mineAccuScores);

            appLogin.setVer(appLogin.getVer() + 1);
            appLogin.setRealName(name);
            appLogin.setPhone(phone);
            cacheService.putData(appLogin.getToken(), appLogin);

        }
    }
    @Transactional
    public Object saveHome(@RequestBody DoOwnerVo doOwnerVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doOwnerVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doOwnerVo.getListHomeInfo(), RESULT_CODE.MESSAGE, "无绑定信息");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doOwnerVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }


        ListOwnerInfo listOwnerInfo = getAssOwner(doOwnerVo.getListHomeInfo().getOwnerBid());
        if (!checkMd5(appLogin, listOwnerInfo, doOwnerVo.getCheckCode(), false)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.DENIED,"share01");
        }


        updateRealName(appLogin, doOwnerVo.getListHomeInfo().getName(),doOwnerVo.getListHomeInfo().getPhone());

        if (EmptyChecker.isEmpty(doOwnerVo.getListHomeInfo().getStatus())) {
            doOwnerVo.getListHomeInfo().setUserBid(appLogin.getBid());
            if (hasHomerExist(appLogin, doOwnerVo.getListHomeInfo().getOwnerBid(),
                    doOwnerVo.getListHomeInfo().getBuildingNo(),
                    doOwnerVo.getListHomeInfo().getHomeNo())) {
                doOwnerVo.getListHomeInfo().setStatus(NEED_CHECK);
            } else {
                doOwnerVo.getListHomeInfo().setStatus(RX_STATUS.NORMAL.getCode());
            }
        }

        if (EmptyChecker.notEmpty(doOwnerVo.getListHomeInfo().getBuildingNo()) &&
                EmptyChecker.notEmpty(doOwnerVo.getListHomeInfo().getHomeNo())
        ) {

            doOwnerVo.getListHomeInfo().setLocation(
                    doOwnerVo.getListHomeInfo().getBuildingNo() +
                            doOwnerVo.getListHomeInfo().getHomeNo());

            cacheService.deleteHomeData(
                    doOwnerVo.getListHomeInfo().getOwnerBid() +
                            doOwnerVo.getListHomeInfo().getUserBid()
            );
        }


        ListHomeInfo listHomeInfo = (ListHomeInfo) ListHomeInfo.create(ListHomeInfo.class, HANDLER_TYPE.SINGLE_BATCH_SAVE);
        listHomeInfo.setDataList(Arrays.asList(doOwnerVo.getListHomeInfo()));
        return standardService.batchSave(listHomeInfo);

    }

    private List<ListHomeInfo> hasHomeList(DoOwnerVo doOwnerVo,String userBid)throws IllegalAccessException, InstantiationException {
        Object obj = cacheService.getHomeData(doOwnerVo.getBid() + userBid);
        List<ListHomeInfo> list;
        ListHomeInfo listHomeInfo = (ListHomeInfo) ListHomeInfo.create(ListHomeInfo.class, HANDLER_TYPE.SINGLE_LIST);
        listHomeInfo.setPageSize(doOwnerVo.getPageSize());
        listHomeInfo.setPageNum(doOwnerVo.getPageNum());
        listHomeInfo.setOwnerBid(doOwnerVo.getBid());
        if (EmptyChecker.isEmpty(obj)) {
            listHomeInfo.setUserBid(userBid);
            list = RxUtil.result(standardService.searchList(listHomeInfo));
            cacheService.putHomeData(doOwnerVo.getBid() + userBid, list);
        } else {
            list = (List) obj;
        }
        return list;
    }

    public Object homePage(@RequestBody DoOwnerVo doOwnerVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doOwnerVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doOwnerVo.getBid(), RESULT_CODE.MESSAGE, "无小区");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doOwnerVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }

        ListOwnerInfo listOwnerInfo = getAssOwner(doOwnerVo.getBid());
        if (!checkMd5(appLogin, listOwnerInfo, doOwnerVo.getCheckCode())) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.DENIED,"share01,share02,share03");
        }

        ListHomeInfo listHomeInfo = (ListHomeInfo) ListHomeInfo.create(ListHomeInfo.class, HANDLER_TYPE.SINGLE_PAGE);
        listHomeInfo.setPageSize(doOwnerVo.getPageSize());
        listHomeInfo.setPageNum(doOwnerVo.getPageNum());
        listHomeInfo.setOwnerBid(doOwnerVo.getBid());

        if("05".equalsIgnoreCase(doOwnerVo.getOperate())){
            // 已通过审核
            listHomeInfo.setStatus(RX_STATUS.NORMAL.getCode());
        }



        List<ListHomeInfo> list = hasHomeList(doOwnerVo,appLogin.getBid());
        if (EmptyChecker.notEmpty(list)) {
            Map<String, Object> condition = new HashMap<>();
            condition.put("inLocation", list.stream().map(e->e.getLocation()).collect(Collectors.toList()));
            listHomeInfo.setCondition(condition);
        }else{
            return Collections.emptyList();
        }

        listHomeInfo.setUserBid(null);
        RxUtil.SQL.desc(listHomeInfo,"id");
        return RxUtil.result(standardService.searchPage(listHomeInfo));
    }
    @Transactional
    public Object batchDelete(@RequestBody DoCommonVo doOwnerVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doOwnerVo.getToken(), RESULT_CODE.MESSAGE, "未登录");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doOwnerVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }

        ListOwnerInfo listOwnerInfo = getAssOwner(doOwnerVo.getOwnerBid());
        if (!checkMd5(appLogin, listOwnerInfo, doOwnerVo.getCheckCode(), false)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.DENIED,"share01");
        }

        ListHomeInfo listHomeInfo = (ListHomeInfo) ListHomeInfo.create(ListHomeInfo.class, HANDLER_TYPE.SINGLE_BATCH_SAVE);

        List<RxBaseData> list = new ArrayList<>();
        for (RxBaseDbMust rxBaseDbMust : doOwnerVo.getDeleteList()) {
            list.add(rxBaseDbMust);
        }
        listHomeInfo.setDataList(list);

        return standardService.batchDelete(listHomeInfo);

    }
    @Transactional
    public Object saveVisit(@RequestBody DoOwnerVo doOwnerVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doOwnerVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doOwnerVo.getListVisitInfo(), RESULT_CODE.MESSAGE, "无来访信息");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doOwnerVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }


        ListVisitInfo visitInfo = doOwnerVo.getListVisitInfo();
        visitInfo.setLocation(visitInfo.getBuildingNo() +visitInfo.getHomeNo());
        updateRealName(appLogin, visitInfo.getVisitor(),visitInfo.getPhone());


        Object obj = cacheService.getHomeData(visitInfo.getOwnerBid() + appLogin.getBid()+visitInfo.getLocation());
        RxUtil.CheckUtil.condition(EmptyChecker.notEmpty(obj), RESULT_CODE.MESSAGE, "记录已存在");

        if(EmptyChecker.isEmpty(visitInfo.getStatus())){
            visitInfo.setStatus(RX_STATUS.NORMAL.getCode());
        }
        if(EmptyChecker.isEmpty(visitInfo.getUserBid())){
            visitInfo.setUserBid(RxBaseConstant.BID_DEFAULT);
        }
        visitInfo.setVisitBid(appLogin.getBid());
        visitInfo.resetHandlerType(HANDLER_TYPE.SINGLE_INSERT);
        visitInfo.getHandlerController().onlyDefault();

        if(EmptyChecker.isEmpty(visitInfo.getVisitor())){
            visitInfo.setVisitor(appLogin.getRealName());
        }


        Object result = standardService.insert(visitInfo);
        cacheService.putHomeData(visitInfo.getOwnerBid() + appLogin.getBid()+visitInfo.getLocation(),result);

        return result;
    }
    @Transactional
    public Object auditVisit(@RequestBody DoOwnerVo doOwnerVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doOwnerVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doOwnerVo.getListVisitInfo(), RESULT_CODE.MESSAGE, "无来访信息");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doOwnerVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }

        ListVisitInfo visitInfo = doOwnerVo.getListVisitInfo();
        ListOwnerInfo listOwnerInfo = getAssOwner(visitInfo.getOwnerBid());
        if (!checkMd5(appLogin, listOwnerInfo, doOwnerVo.getCheckCode(), false)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.DENIED,"share01");
        }


        if(EmptyChecker.notEmpty(visitInfo.getValid())){
            visitInfo.setValid(null);
            visitInfo.resetHandlerType(HANDLER_TYPE.SINGLE_DELETE);
            return standardService.delete(visitInfo);
        }
        visitInfo.resetHandlerType(HANDLER_TYPE.SINGLE_UPDATE);
        visitInfo.setUserBid(appLogin.getBid());
        visitInfo.setStatus(HAVE_CHECK);
        return standardService.update(visitInfo);

    }
    public Object visitPage(@RequestBody DoOwnerVo doOwnerVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doOwnerVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doOwnerVo.getBid(), RESULT_CODE.MESSAGE, "无小区");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doOwnerVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }
        ListOwnerInfo listOwnerInfo = getAssOwner(doOwnerVo.getBid());
        if (!checkMd5(appLogin, listOwnerInfo, doOwnerVo.getCheckCode())) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.DENIED,"share01,share02,share03");
        }
        ListVisitInfo listVisitInfo = (ListVisitInfo) ListVisitInfo.create(ListVisitInfo.class, HANDLER_TYPE.SINGLE_LIST);
        listVisitInfo.setPageSize(doOwnerVo.getPageSize());
        listVisitInfo.setPageNum(doOwnerVo.getPageNum());
        listVisitInfo.setOwnerBid(doOwnerVo.getBid());

        if ("01".equalsIgnoreCase(doOwnerVo.getOperate())){
            // 审批通行查询
            listVisitInfo.setStatus(NEED_CHECK);
            List<ListHomeInfo> list = hasHomeList(doOwnerVo,appLogin.getBid());
            listVisitInfo.setUserBid(RxBaseConstant.BID_DEFAULT);
            listVisitInfo.setName(appLogin.getRealName());
            if (EmptyChecker.notEmpty(list)) {
                Map<String, Object> condition = new HashMap<>();
                condition.put("inLocation", list.stream().map(e->e.getLocation()).collect(Collectors.toList()));
                listVisitInfo.setCondition(condition);
            }else {
                Collections.emptyList();
            }
        }else{
            Map<String, Object> condition = new HashMap<>();
            condition.put("inStatus", Arrays.asList(RX_STATUS.NORMAL.getCode(),HAVE_CHECK));
            listVisitInfo.setCondition(condition);
        }

        //排序
        RxUtil.SQL.desc(listVisitInfo,"id");
        return RxUtil.result(standardService.searchPage(listVisitInfo));
    }

    public Object obtainVisit(@RequestBody DoOwnerVo doOwnerVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doOwnerVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doOwnerVo.getBid(), RESULT_CODE.MESSAGE, "无小区");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doOwnerVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }

        ListVisitInfo listVisitInfo = (ListVisitInfo) ListVisitInfo.create(ListVisitInfo.class, HANDLER_TYPE.SINGLE_LIST);
        listVisitInfo.setOwnerBid(doOwnerVo.getBid());
        listVisitInfo.setVisitBid(appLogin.getBid());
        listVisitInfo.setStatus(HAVE_CHECK);

        Map<String,Object> conditon = new HashMap<>();
        // 大于一个小时前
        conditon.put("gtUpdateDate",new Date(new Date().getTime() - 3600000));
        listVisitInfo.setCondition(conditon);
        //排序
        RxUtil.SQL.desc(listVisitInfo,"id");

        List<ListVisitInfo> list = RxUtil.result(standardService.searchList(listVisitInfo));
        RxUtil.CheckUtil.check(list, RESULT_CODE.MESSAGE, "无授权");



        ListOwnerInfo listOwnerInfo = getAssOwner(doOwnerVo.getBid());

        DoShareKeyVo shareKeyVo = new DoShareKeyVo();
        shareKeyVo.setRealName(list.get(0).getName());
        shareKeyVo.setHomeNo(list.get(0).getHomeNo());
        shareKeyVo.setBuildingNo(list.get(0).getBuildingNo());
        shareKeyVo.setShareBid(list.get(0).getUserBid());
        shareKeyVo.setBid(list.get(0).getOwnerBid());
        shareKeyVo.setName(list.get(0).getOwnerName());
        shareKeyVo.setStatus(listOwnerInfo.getStatus());
        shareKeyVo.setRandom(reverse(listOwnerInfo.getKeyRandom()));
        return shareKeyVo;
    }

    private void checkMd5( ListLoginVo appLogin,String bid,String checkCode, NotReturnMode handle02,NotReturnMode handle03,NotReturnMode handle01) throws IllegalAccessException, InstantiationException {
        ListOwnerInfo listOwnerInfo = getAssOwner(bid);
        if (checkMd5(appLogin, listOwnerInfo, checkCode,"02")) {
            // 业委
            if(EmptyChecker.notEmpty(handle02))handle02.handle();
        }else if (checkMd5(appLogin, listOwnerInfo, checkCode,"03")) {
            // 物业
            if(EmptyChecker.notEmpty(handle03))handle03.handle();

        }else if (checkMd5(appLogin, listOwnerInfo, checkCode,"01")) {
            // 业主

            if(EmptyChecker.notEmpty(handle01))handle01.handle();

        }else{
            RxUtil.CheckUtil.throwOut(RESULT_CODE.DENIED,"share01,share02,share03");
        }
    }

    public Object memberPage(@RequestBody DoMemberVo doOwnerVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doOwnerVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doOwnerVo.getBid(), RESULT_CODE.MESSAGE, "无小区");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doOwnerVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }
        ListOwnerInfo listOwnerInfo = getAssOwner(doOwnerVo.getBid());
        DoubleListMemberInfo condition = (DoubleListMemberInfo) RxBaseData.create(DoubleListMemberInfo.class, ListMaterialInfo.class, HANDLER_TYPE.DOUBLE_PAGE);

        condition.setStatus(RX_STATUS.NORMAL.getCode());
        checkMd5(appLogin, doOwnerVo.getBid(), doOwnerVo.getCheckCode(),()->{
            condition.conditionMap().put("inStatus",Arrays.asList(RX_STATUS.NORMAL.getCode(),NEED_CHECK));
            condition.setStatus(null);
            },null,null);

        ListMaterialInfo relation = (ListMaterialInfo) condition.obtainRelation();
        relation.setStatus(RX_STATUS.NORMAL.getCode());
        relation.appendSqlFilter(Arrays.asList(DoubleListMemberInfo.UPDATE_DATE,  DoubleListMemberInfo.VALID));

        condition.setReturnType(DoubleListMemberInfo.ASS_BID);

        // 不查询某个字段
        condition.appendSqlFilter(Arrays.asList(DoubleListMemberInfo.UPDATE_DATE,  DoubleListMemberInfo.VALID));

        condition.setPageNum(doOwnerVo.getPageNum());
        condition.setPageSize(doOwnerVo.getPageSize());
        condition.setOwnerBid(doOwnerVo.getBid());

        if(EmptyChecker.notEmpty(doOwnerVo.getMemberInfo())){
            condition.setSession(doOwnerVo.getMemberInfo().getSession());
        }
        RxUtil.SQL.desc(condition,"id");
        List<DoubleListMemberInfo> list = RxUtil.result(standardService.innerSearchPage(condition));


        return list;
    }

    public Object memberHiPage(@RequestBody DoMemberVo doOwnerVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doOwnerVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doOwnerVo.getBid(), RESULT_CODE.MESSAGE, "无小区");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doOwnerVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }

        ListOwnerInfo listOwnerInfo = getAssOwner(doOwnerVo.getBid());
        if (!checkMd5(appLogin, listOwnerInfo, doOwnerVo.getCheckCode())) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.DENIED,"share01,share02,share03");
        }

        ListMemberInfo listMemberInfo = (ListMemberInfo) RxBaseData.create(ListMemberInfo.class, HANDLER_TYPE.SINGLE_PAGE);

        listMemberInfo.setPageNum(doOwnerVo.getPageNum());
        listMemberInfo.setPageSize(doOwnerVo.getPageSize());
        listMemberInfo.setOwnerBid(doOwnerVo.getBid());

        RxUtil.SQL.groupBy(listMemberInfo,"session");
        RxUtil.SQL.desc(listMemberInfo,"id");
        List<ListMemberInfo> list = RxUtil.result(standardService.searchPage(listMemberInfo));

        return list;
    }

    private  List getMineInfo(ListLoginVo appLogin)throws IllegalAccessException, InstantiationException {

        ListMaterialInfo listMaterialInfo = (ListMaterialInfo) RxBaseData.create(ListMaterialInfo.class, HANDLER_TYPE.SINGLE_LIST);
        listMaterialInfo.setUserBid(appLogin.getBid());
        listMaterialInfo.setStatus(RX_STATUS.NORMAL.getCode());
        RxUtil.SQL.desc(listMaterialInfo,"id");
        List<ListMaterialInfo> list = RxUtil.result(standardService.searchList(listMaterialInfo));

        return list;
    }

    @Transactional
    public Object materialSave(@RequestBody DoMemberVo doOwnerVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doOwnerVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doOwnerVo.getMaterialInfo(), RESULT_CODE.MESSAGE, "无材料");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doOwnerVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }

        ListMaterialInfo materialInfo = new ListMaterialInfo();
        materialInfo.resetHandlerType(HANDLER_TYPE.SINGLE_BATCH_SAVE);
//        List<RxBaseData> list = new ArrayList<>();
//        list.add(doOwnerVo.getMaterialInfo());
        doOwnerVo.getMaterialInfo().setStatus(RX_STATUS.NORMAL.getCode());
        doOwnerVo.getMaterialInfo().setUserBid(appLogin.getBid());

        materialInfo.setDataList(Arrays.asList(doOwnerVo.getMaterialInfo()));
        standardService.batchSave(materialInfo);
        return materialInfo.getDataList().get(0);
    }

    public Object materialList(@RequestBody DoMemberVo doOwnerVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doOwnerVo.getToken(), RESULT_CODE.MESSAGE, "未登录");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doOwnerVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }

        if("01".equalsIgnoreCase(doOwnerVo.getOperate())){
            // 本人最新资料
            return getMineInfo(appLogin);
        }
        RxUtil.CheckUtil.check(doOwnerVo.getBid(), RESULT_CODE.MESSAGE, "无小区");
        ListOwnerInfo listOwnerInfo = getAssOwner(doOwnerVo.getBid());
        if (!checkMd5(appLogin, listOwnerInfo, doOwnerVo.getCheckCode())) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.DENIED,"share01,share02,share03");
        }
        ListMaterialInfo listMaterialInfo = (ListMaterialInfo) RxBaseData.create(ListMaterialInfo.class, HANDLER_TYPE.SINGLE_PAGE);
        listMaterialInfo.setPageNum(doOwnerVo.getPageNum());
        listMaterialInfo.setPageSize(doOwnerVo.getPageSize());
        listMaterialInfo.setOwnerBid(doOwnerVo.getBid());

        List<ListMaterialInfo> list = RxUtil.result(standardService.searchPage(listMaterialInfo));

        boolean needSelf = true;
        for (ListMaterialInfo materialInfo : list) {

            materialInfo.appendFilter(Arrays.asList(
                    RxUtil.StringUtil.lineToHump(ListMaterialInfo.UPDATE_DATE),
                    RxUtil.StringUtil.lineToHump(ListMaterialInfo.VER),
                    RxUtil.StringUtil.lineToHump(ListMaterialInfo.DESC),
                    RxUtil.StringUtil.lineToHump(ListMaterialInfo.USER_BID),
                    RxUtil.StringUtil.lineToHump(ListMaterialInfo.VALID),
                    RxUtil.StringUtil.lineToHump(ListMaterialInfo.OWNER_BID),
                    RxUtil.StringUtil.lineToHump(ListMaterialInfo.OWNER_NAME)));
            if(appLogin.getBid().equalsIgnoreCase(materialInfo.getUserBid())){
                needSelf = false;
            }
        }

        if(needSelf){
            List<ListMaterialInfo> infoList = getMineInfo(appLogin);
            if(EmptyChecker.notEmpty(infoList)){
                infoList.get(0).appendFilter(Arrays.asList(
                        RxUtil.StringUtil.lineToHump(ListMaterialInfo.UPDATE_DATE),  RxUtil.StringUtil.lineToHump(ListMaterialInfo.VER),
                        RxUtil.StringUtil.lineToHump(ListMaterialInfo.DESC),RxUtil.StringUtil.lineToHump(ListMaterialInfo.USER_BID),

                        RxUtil.StringUtil.lineToHump(ListMaterialInfo.VALID),RxUtil.StringUtil.lineToHump(ListMaterialInfo.OWNER_BID),
                        RxUtil.StringUtil.lineToHump(ListMaterialInfo.OWNER_NAME)));

                list.add(infoList.get(0));
            }
        }

        return list;
    }


    @Transactional
    public Object saveMember(@RequestBody DoMemberVo doOwnerVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doOwnerVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doOwnerVo.getMemberInfo(), RESULT_CODE.MESSAGE, "无信息");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doOwnerVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }
        RxUtil.CheckUtil.check(doOwnerVo.getMemberInfo().getOwnerBid(), RESULT_CODE.MESSAGE, "无小区");
        ListOwnerInfo listOwnerInfo = getAssOwner(doOwnerVo.getMemberInfo().getOwnerBid());
        if (!checkMd5(appLogin, listOwnerInfo, doOwnerVo.getCheckCode(),"02")) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.DENIED,"share02");
        }

        ListMemberInfo memberInfo = doOwnerVo.getMemberInfo();
        memberInfo.resetHandlerType(HANDLER_TYPE.SINGLE_BATCH_SAVE);
        if(EmptyChecker.isEmpty(memberInfo.getBid())){
            memberInfo.setStatus(NEED_CHECK);
            return standardService.insert(memberInfo);
        }else {
            return standardService.update(memberInfo);
        }

    }
    @Transactional
    public Object deleteMember(@RequestBody DoMemberVo doOwnerVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doOwnerVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doOwnerVo.getBid(), RESULT_CODE.MESSAGE, "无小区");
        RxUtil.CheckUtil.check(doOwnerVo.getMemberInfoList(), RESULT_CODE.MESSAGE, "无信息");
        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doOwnerVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }

        RxUtil.CheckUtil.check(doOwnerVo.getBid(), RESULT_CODE.MESSAGE, "无小区");
        ListOwnerInfo listOwnerInfo = getAssOwner(doOwnerVo.getBid());
        if (!checkMd5(appLogin, listOwnerInfo, doOwnerVo.getCheckCode(),"02")) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.DENIED,"share02");
        }

        List<RxBaseData> list = new ArrayList<>();
        for (RxBaseDbMust rxBaseDbMust : doOwnerVo.getMemberInfoList()) {
            list.add(rxBaseDbMust);
        }
        ListMemberInfo info = new ListMemberInfo();
        info.setDataList(list);
        return standardService.batchDelete(info);
    }

    private void checkNotice(DoNoticeVo doNoticeVo,ListLoginVo appLogin,ListEssayInfo essayInfo ) throws IllegalAccessException, InstantiationException {
        ListOwnerInfo listOwnerInfo = getAssOwner(doNoticeVo.getBid());
        if (checkMd5(appLogin, listOwnerInfo, doNoticeVo.getCheckCode(),"02")) {
            // 业委
            if("02".equalsIgnoreCase(doNoticeVo.getOperate())){
                Map<String,Object> map= essayInfo.conditionMap();
                map.put("inStatus",Arrays.asList(RX_STATUS.NORMAL.getCode(),NEED_CHECK));
            }else{
                essayInfo.setStatus(RX_STATUS.NORMAL.getCode());
            }

        }else if (checkMd5(appLogin, listOwnerInfo, doNoticeVo.getCheckCode(),"03")) {
            // 物业
            essayInfo.setReadRight(RX_STATUS.NORMAL.getCode());
            if("03".equalsIgnoreCase(doNoticeVo.getOperate())){
                Map<String,Object> map= essayInfo.conditionMap();
                map.put("inStatus",Arrays.asList(RX_STATUS.NORMAL.getCode(),NEED_CHECK));
            }else{
                essayInfo.setStatus(RX_STATUS.NORMAL.getCode());
                Map<String,Object> map= essayInfo.conditionMap();
                map.put("inReadRight",Arrays.asList(RX_STATUS.NORMAL.getCode(),WY_NO_QUERY));
            }

        }else if (checkMd5(appLogin, listOwnerInfo, doNoticeVo.getCheckCode(),"01")) {
            // 业主

            essayInfo.setStatus(RX_STATUS.NORMAL.getCode());
        }else{
            RxUtil.CheckUtil.throwOut(RESULT_CODE.DENIED,"share01,share02,share03");
        }
    }
    private boolean checkSaveNotice(DoNoticeVo doNoticeVo,ListLoginVo appLogin) throws IllegalAccessException, InstantiationException {
        ListOwnerInfo listOwnerInfo = getAssOwner(doNoticeVo.getBid());

        if("04".equalsIgnoreCase(doNoticeVo.getOperate())){
            // 物业报修
            if (checkMd5(appLogin, listOwnerInfo, doNoticeVo.getCheckCode(),true)) {
                return false;
            }else if (checkMd5(appLogin, listOwnerInfo, doNoticeVo.getCheckCode(),"01")) {
                return true;
            }

        }
        if (checkMd5(appLogin, listOwnerInfo, doNoticeVo.getCheckCode(),"02")) {
            // 业委
            if("02".equalsIgnoreCase(doNoticeVo.getOperate())){
                return false;
            }

        }else if (checkMd5(appLogin, listOwnerInfo, doNoticeVo.getCheckCode(),"03")) {
            // 物业

            if("03".equalsIgnoreCase(doNoticeVo.getOperate())){
                return false;
            }

        }
        RxUtil.CheckUtil.throwOut(RESULT_CODE.MESSAGE,"无权保存");
        return false;
    }

    public Object essayPageForRepair(ListLoginVo appLogin, DoNoticeVo doNoticeVo) throws IllegalAccessException, InstantiationException {
        ListEssayInfo essayInfo = new ListEssayInfo();
        essayInfo.resetHandlerType(HANDLER_TYPE.SINGLE_PAGE);
        essayInfo.setFileFlg(doNoticeVo.getFileFlg());
        essayInfo.setPageNum(doNoticeVo.getPageNum());
        essayInfo.setPageSize(doNoticeVo.getPageSize());
        essayInfo.setAssBid(doNoticeVo.getBid());
        essayInfo.setType(doNoticeVo.getOperate());

        ListOwnerInfo listOwnerInfo = getAssOwner(doNoticeVo.getBid());
        List<ListEssayInfo> list=new ArrayList<>();
        if (checkMd5(appLogin, listOwnerInfo, doNoticeVo.getCheckCode(),true)) {
            list = essayInfoMapper.selectCheckPage(essayInfo);
        } else if (checkMd5(appLogin, listOwnerInfo, doNoticeVo.getCheckCode(),"01")) {
            essayInfo.setCreateBid(appLogin.getBid());
            list= essayInfoMapper.selectNormalPage(essayInfo);
        }else{
            RxUtil.CheckUtil.throwOut(RESULT_CODE.MESSAGE,"无权查看");
        }
        if(EmptyChecker.notEmpty(list)){
            for (ListEssayInfo listEssayInfo : list) {
                listEssayInfo.removeFilter(Arrays.asList(RxUtil.StringUtil.lineToHump(ListEssayInfo.CREATE_DATE)));
            }
        }

        return list;
    }
    public Object essayPage(@RequestBody DoNoticeVo doNoticeVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doNoticeVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doNoticeVo.getBid(), RESULT_CODE.MESSAGE, "无小区");
        RxUtil.CheckUtil.check(doNoticeVo.getOperate(), RESULT_CODE.MESSAGE, "公告类型");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doNoticeVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }

        if("04".equalsIgnoreCase(doNoticeVo.getOperate())){
            return essayPageForRepair(appLogin,doNoticeVo);
        }

        ListEssayInfo essayInfo = new ListEssayInfo();
        essayInfo.resetHandlerType(HANDLER_TYPE.SINGLE_PAGE);

        checkNotice(doNoticeVo,appLogin,essayInfo);
        essayInfo.setFileFlg(doNoticeVo.getFileFlg());
        essayInfo.setPageNum(doNoticeVo.getPageNum());
        essayInfo.setPageSize(doNoticeVo.getPageSize());
        essayInfo.setAssBid(doNoticeVo.getBid());
        essayInfo.setType(doNoticeVo.getOperate());

        essayInfo.onlySqlSelect(Arrays.asList(ListEssayInfo.UPDATE_DATE,ListEssayInfo.BID,ListEssayInfo.VER,ListEssayInfo.READ_RIGHT,
                ListEssayInfo.STATUS, ListEssayInfo.CHECK_NAME,ListEssayInfo.CREATE_NAME,ListEssayInfo.CREATE_BID,ListEssayInfo.TITLE));

        RxUtil.SQL.desc(essayInfo,"id");
        return RxUtil.result(standardService.searchPage(essayInfo));
    }
    public Object completeEssay(@RequestBody DoNoticeVo doNoticeVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doNoticeVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doNoticeVo.getBid(), RESULT_CODE.MESSAGE, "无小区");
        RxUtil.CheckUtil.check(doNoticeVo.getOperate(), RESULT_CODE.MESSAGE, "公告类型");
        RxUtil.CheckUtil.check(doNoticeVo.getEssayInfo(), RESULT_CODE.MESSAGE, "内容");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doNoticeVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }
        RxUtil.CheckUtil.check(appLogin.getRealName(), RESULT_CODE.MESSAGE, "无实名");
        checkSaveNotice(doNoticeVo,appLogin);
        ListEssayInfo essayInfo = doNoticeVo.getEssayInfo();
        RxUtil.CheckUtil.check(essayInfo.getBid(), RESULT_CODE.MESSAGE, "记录不存在");

        essayInfo.setUpdateDate(new Date());
        essayInfo.setCheckBid(appLogin.getBid());
        essayInfo.setCheckName(appLogin.getRealName());
        return standardService.update(essayInfo);
    }
    @Transactional
    public Object saveEssay(@RequestBody DoNoticeVo doNoticeVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doNoticeVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doNoticeVo.getBid(), RESULT_CODE.MESSAGE, "无小区");
        RxUtil.CheckUtil.check(doNoticeVo.getOperate(), RESULT_CODE.MESSAGE, "公告类型");
        RxUtil.CheckUtil.check(doNoticeVo.getEssayInfo(), RESULT_CODE.MESSAGE, "内容");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doNoticeVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }
        RxUtil.CheckUtil.check(appLogin.getRealName(), RESULT_CODE.MESSAGE, "无实名");

        checkSaveNotice(doNoticeVo,appLogin);
        ListEssayInfo essayInfo = doNoticeVo.getEssayInfo();
        essayInfo.setType(doNoticeVo.getOperate());
        if(EmptyChecker.isEmpty(essayInfo.getBid())){
            essayInfo.setStatus(NEED_CHECK);
            essayInfo.setCreateBid(appLogin.getBid());
            essayInfo.setCreateName(appLogin.getRealName());
            standardService.insert(essayInfo);
            return essayInfo;
        }else {
            if(appLogin.getBid().equalsIgnoreCase(essayInfo.getCreateBid())){
                essayInfo.setStatus(NEED_CHECK);
            }else {
                essayInfo.setCheckBid(appLogin.getBid());
                essayInfo.setCheckName(appLogin.getRealName());
            }
            standardService.update(essayInfo);
        }
        return Integer.valueOf(1);
    }

    public Object obtainEssay(@RequestBody DoNoticeVo doNoticeVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doNoticeVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doNoticeVo.getBid(), RESULT_CODE.MESSAGE, "无小区");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doNoticeVo.getToken());
        RxUtil.CheckUtil.check(appLogin, RESULT_CODE.LOGIN_ERR, "未登录");


        ListEssayInfo essayInfo = new ListEssayInfo();
        essayInfo.resetHandlerType(HANDLER_TYPE.SINGLE_DETAIL);
        essayInfo.getHandlerController().onlyDefault();
        essayInfo.setBid(doNoticeVo.getBid());

        essayInfo.onlySqlSelect(Arrays.asList(ListEssayInfo.ESSAY));

        return standardService.detail(essayInfo);
    }

    @Transactional
    public Object deleteEssay(@RequestBody DoNoticeVo doNoticeVo) throws IllegalAccessException, InstantiationException {

        RxUtil.CheckUtil.check(doNoticeVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doNoticeVo.getBid(), RESULT_CODE.MESSAGE, "无小区");
        RxUtil.CheckUtil.check(doNoticeVo.getOperate(), RESULT_CODE.MESSAGE, "公告类型");
        RxUtil.CheckUtil.check(doNoticeVo.getDeleteList(), RESULT_CODE.MESSAGE, "内容");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doNoticeVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }

        checkSaveNotice(doNoticeVo,appLogin);

        List<RxBaseData> list = new ArrayList<>();
        for (RxBaseDbMust rxBaseDbMust : doNoticeVo.getDeleteList()) {
            list.add(rxBaseDbMust);
        }
        ListEssayInfo info = new ListEssayInfo();
        info.setDataList(list);
        return standardService.batchDelete(info);
    }

    private boolean checkThumps(String bid,String hash){
        int location = bid.hashCode() & (16383);
        int index = location / 8;
        int bit = location % 8;
        byte by = hash.getBytes()[index];

        return (by&(1 << bit)) != 0;
    }

    private String setThumps(String bid,String hash,boolean yes){
        int location = bid.hashCode() & (16383);
        int index = location / 8;
        int bit = location % 8;
        byte[] bytes = hash.getBytes();
        byte by =bytes[index];
        if(yes){
            by= (byte)(by | (1 << bit)& 0xFF);
        }else {
            by = (byte)(by & ~(1 << bit)& 0xFF);
        }
        bytes[index] = by;
        return new String(bytes);
    }

    public Object schedulePage(@RequestBody DoNoticeVo doNoticeVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doNoticeVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doNoticeVo.getBid(), RESULT_CODE.MESSAGE, "无小区");
        RxUtil.CheckUtil.check(doNoticeVo.getOperate(), RESULT_CODE.MESSAGE, "公告类型");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doNoticeVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }


        ListScheduleInfo scheduleInfo = new ListScheduleInfo();
        scheduleInfo.resetHandlerType(HANDLER_TYPE.SINGLE_PAGE);
        ListOwnerInfo listOwnerInfo = getAssOwner(doNoticeVo.getBid());
        if (!checkMd5(appLogin, listOwnerInfo, doNoticeVo.getCheckCode())) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.DENIED,"share02");
        }

        scheduleInfo.setPageNum(doNoticeVo.getPageNum());
        scheduleInfo.setPageSize(doNoticeVo.getPageSize());
        scheduleInfo.setAssBid(doNoticeVo.getAssBid());
//        scheduleInfo.onlySqlSelect(Arrays.asList(ListScheduleInfo.UPDATE_DATE,ListScheduleInfo.BID,ListScheduleInfo.VER,ListScheduleInfo.NAME,
//                ListScheduleInfo.STATUS, ListScheduleInfo.DESCRIPTION,ListScheduleInfo.COMPLETE,ListScheduleInfo.UP_COUNT,ListScheduleInfo.DOWN_COUNT,ListScheduleInfo.ASS_BID));

        RxUtil.SQL.desc(scheduleInfo,"id");
        List<ListScheduleInfo> list =  RxUtil.result(standardService.searchPage(scheduleInfo));

        for (ListScheduleInfo info : list) {
            info.setUpTrue(checkThumps(appLogin.getBid(),info.getUpHash())?"1":"0");
            info.setDownTrue(checkThumps(appLogin.getBid(),info.getDownHash())?"1":"0");
            info.appendFilter(Arrays.asList(RxUtil.StringUtil.lineToHump(ListScheduleInfo.DOWN_HASH),
                    RxUtil.StringUtil.lineToHump(ListScheduleInfo.UP_HASH)));
        }
        return list;
    }

    @Transactional
    public Object saveSchedule(@RequestBody DoNoticeVo doNoticeVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doNoticeVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doNoticeVo.getBid(), RESULT_CODE.MESSAGE, "无小区");
        RxUtil.CheckUtil.check(doNoticeVo.getScheduleInfoList(), RESULT_CODE.MESSAGE, "无内容");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doNoticeVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }

        checkSaveNotice(doNoticeVo,appLogin);
        ListScheduleInfo info = new ListScheduleInfo();
        info.resetHandlerType(HANDLER_TYPE.SINGLE_BATCH_SAVE);
        info.getHandlerController().onlyDefault();
        List<RxBaseData> list = new ArrayList<>();
        for (ListScheduleInfo scheduleInfo : doNoticeVo.getScheduleInfoList()) {
            if(EmptyChecker.isEmpty(scheduleInfo.getAssBid())) {
                scheduleInfo.setAssBid(doNoticeVo.getAssBid());
            }
            scheduleInfo.setUpCount((Integer) RxUtil.ofNull(scheduleInfo.getUpCount(),0));
            scheduleInfo.setDownCount((Integer) RxUtil.ofNull(scheduleInfo.getDownCount(),0));
            if(EmptyChecker.isEmpty(scheduleInfo.getBid())){
                byte[] bytes = new byte[2048];
                java.util.Arrays.fill(bytes, (byte) 0);
                scheduleInfo.setUpHash(new String(bytes));
                scheduleInfo.setDownHash(new String(bytes));

            }
            scheduleInfo.setUpTrue(null);
            scheduleInfo.setDownTrue(null);
            list.add(scheduleInfo);
        }
        info.setDataList(list);
        return standardService.batchSave(info);
    }

    @Transactional
    public Object deleteSchedule(@RequestBody DoNoticeVo doNoticeVo) throws IllegalAccessException, InstantiationException {

        RxUtil.CheckUtil.check(doNoticeVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doNoticeVo.getBid(), RESULT_CODE.MESSAGE, "无小区");
        RxUtil.CheckUtil.check(doNoticeVo.getOperate(), RESULT_CODE.MESSAGE, "公告类型");
        RxUtil.CheckUtil.check(doNoticeVo.getDeleteList(), RESULT_CODE.MESSAGE, "无内容");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doNoticeVo.getToken());
        if (EmptyChecker.isEmpty(appLogin)) {
            RxUtil.CheckUtil.throwOut(RESULT_CODE.LOGIN_ERR, "未登录");
        }

        checkSaveNotice(doNoticeVo,appLogin);

        List<RxBaseData> list = new ArrayList<>();
        for (RxBaseDbMust rxBaseDbMust : doNoticeVo.getDeleteList()) {
            list.add(rxBaseDbMust);
        }
        ListScheduleInfo info = new ListScheduleInfo();
        info.setDataList(list);
        return standardService.batchDelete(info);
    }

    @Transactional
    public Object thumbsSchedule(@RequestBody DoNoticeVo doNoticeVo) throws IllegalAccessException, InstantiationException {
        RxUtil.CheckUtil.check(doNoticeVo.getToken(), RESULT_CODE.MESSAGE, "未登录");
        RxUtil.CheckUtil.check(doNoticeVo.getBid(), RESULT_CODE.MESSAGE, "无小区");
        RxUtil.CheckUtil.check(doNoticeVo.getScheduleInfoList(), RESULT_CODE.MESSAGE, "无内容");

        ListLoginVo appLogin = (ListLoginVo) cacheService.getData(doNoticeVo.getToken());
        RxUtil.CheckUtil.check(appLogin, RESULT_CODE.LOGIN_ERR, "未登录");



        ListOwnerInfo listOwnerInfo = getAssOwner(doNoticeVo.getBid());
        RxUtil.CheckUtil.condition(!checkMd5(appLogin, listOwnerInfo, doNoticeVo.getCheckCode()), RESULT_CODE.DENIED,"share01,share02,share03");

        ListScheduleInfo scheduleInfoParam = doNoticeVo.getScheduleInfoList().get(0);
        scheduleInfoParam.resetHandlerType(HANDLER_TYPE.SINGLE_LIST);

        String upTrue = scheduleInfoParam.getUpTrue();
        String downTrue = scheduleInfoParam.getDownTrue();
        scheduleInfoParam.setUpTrue(null);
        scheduleInfoParam.setDownTrue(null);

        List<ListScheduleInfo> list = RxUtil.result(standardService.searchList(scheduleInfoParam));
        if(EmptyChecker.isEmpty(list)){
            return Integer.valueOf(0);
        }
        ListScheduleInfo scheduleInfo = list.get(0);
        scheduleInfo.resetHandlerType(HANDLER_TYPE.SINGLE_UPDATE);

        appLogin.getBid().hashCode();


        if("1".equalsIgnoreCase(upTrue)){
            // 点赞
            if(!checkThumps(appLogin.getBid(),scheduleInfo.getUpHash())){
                scheduleInfo.setUpCount(scheduleInfo.getUpCount()+1);
                scheduleInfo.setUpHash(setThumps(appLogin.getBid(),scheduleInfo.getUpHash(),true));
            }

        }else{
            // 取消
            if(checkThumps(appLogin.getBid(),scheduleInfo.getUpHash())){
                scheduleInfo.setUpCount(scheduleInfo.getUpCount()-1);
                scheduleInfo.setUpHash(setThumps(appLogin.getBid(),scheduleInfo.getUpHash(),false));
            }
        }

        if("1".equalsIgnoreCase(downTrue)){
            // 点赞
            if(!checkThumps(appLogin.getBid(),scheduleInfo.getDownHash())){
                scheduleInfo.setDownCount(scheduleInfo.getDownCount()+1);
                scheduleInfo.setDownHash(setThumps(appLogin.getBid(),scheduleInfo.getDownHash(),true));
            }

        }else{
            // 取消
            if(checkThumps(appLogin.getBid(),scheduleInfo.getDownHash())){
                scheduleInfo.setDownCount(scheduleInfo.getDownCount()-1);
                scheduleInfo.setDownHash(setThumps(appLogin.getBid(),scheduleInfo.getDownHash(),false));
            }
        }

        return standardService.update(scheduleInfo);

    }
}
